#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

vector <string> ::iterator VectorFind(string s,vector <string> &vec){
	vector <string> ::iterator p;
	for( p=vec.begin(); p!=vec.end(); p++ ){
		if( *p==s ){
			return p;
		}
	}
	return p;
}

int main(){
int n;
	vector <string> vec;
	vector <string> ::iterator p;
	cin>>n;
	pair <string,string> partner[n];
	for( int i=0; i<n; i++ ){
		cin>>partner[i].first>>partner[i].second;
	}
	vec.push_back(partner[0].first);vec.push_back(partner[0].second ) ;
	cout<<partner[0].first<<endl;
	string s;
	cin>>s;
	cout<<s<<endl;
	p=VectorFind(s,vec);
	vec.erase(p); 
	if( p==vec.end() ){
	printf("fag")	;
	}
	return 0;
}	
